<template>
    <div class="resCommon">
        <div class="search">
            <div class="classify">
                <refresh :loading='syncH' title="同步YARN" @refresh="syncResource" />
                <!-- <el-button class="addResBtn" type="primary" @click="syncResource" title="同步YARN" icon="el-icon-refresh" :loading="syncH"></el-button> -->
            </div>
            <div class="searchBox">
                <el-button :disabled="clickStep==1" class="addResBtn" type="primary" @click="addResOrEditBtn('新建资源',0)">新建资源</el-button>
                <el-button :disabled="clickStep==1" class="addResBtn" type="primary" @click="addResOrEditBtn('编辑资源',1)">编辑资源</el-button>
                <search placeholder="请输入搜索内容名称" :live-search="true" :search-word.sync="searchName" @search="searchCon"/>
            </div>
        </div>
        <!-- 目录面包屑 -->
        <el-breadcrumb separator="/" class="breadcrumb-wrap">
            <el-breadcrumb-item></el-breadcrumb-item>
            <el-breadcrumb-item 
                v-for="(item, index) in breadcrumbList"
                :key="item.id"
                @click.native="onClickBread(item, index)"
            >
                <span class="cursor">{{item.name}}</span>
            </el-breadcrumb-item>
            <el-breadcrumb-item></el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 表格 -->
        <div class="table">
            <el-table :key='toggleIndex' v-loading="loading" :data="resourcePublic" stripe style="width: 100%">
                <el-table-column :label="YARNtableHead[clickStep-1].first">
                    <template slot-scope="scope">
                        <el-button v-if="clickStep==1" @click="menuDetail(scope.row)" type="text">{{scope.row.queueName}}</el-button>
                        <span v-if="clickStep==2">{{scope.row.queueName}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="队列占比(%)">
                    <template slot-scope="scope">
                        <span>{{scope.row.ratio}}</span>
                    </template>
                </el-table-column>
                <el-table-column v-if="clickStep!=1" label="分配的用户">
                    <template slot-scope="scope">
                        <span v-for="(item,index) in scope.row.userList" :key='index'> {{item}} </span>
                    </template>
                </el-table-column>
                <el-table-column v-if="clickStep!=1" label="权限">
                    <template slot-scope="scope">
                        <span>{{scope.row.powerList}}</span>
                    </template>
                </el-table-column>
                <el-table-column v-if="clickStep!=1" label="所属租户">
                    <template slot-scope="scope">
                        <span v-for="(item,index) in scope.row.tenantList" :key='index'> {{item}} </span>
                    </template>
                </el-table-column>
                <el-table-column v-if="clickStep!=1" label="操作">
                    <template slot-scope="scope">
                        <el-tooltip content="分配用户" placement="top">
                            <el-button type="text" @click="tenantBtn(scope.row)">
                                <i class="el-icon-files icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                        <el-tooltip content="删除" placement="top">
                            <el-button type="text" @click="deleteBtn(scope.row)">
                                <i class="el-icon-delete icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 分页(默认 10条/页) -->
        <pagenation :pageInfo='pageinfo'></pagenation>
        <dialogCom :diaData='dialogData'></dialogCom>
    </div>
</template>

<script>
import DialogCom from '@/components/resource/TenantResource';
import Pagenation from '@/components/resource/Pagenation'
import resource from '@/mixins/resource'
import Search from '@/components/common/Search'
    export default {
        components:{DialogCom, Pagenation, Search},
        mixins:[resource],
        data() {
            return {
                pageinfo: {
                    tenantNum: 0,
                    currentPage: 1
                },
                dialogData:{
                    type: 'YARN',
                    label:'队列名',
                    addResourceTab: false,
                    titleTips: '',
                    opeBtn: '',
                    isDisabled: false,
                    operatorTips: '',
                    resOperate: false,
                    editYARN:false
                },
                resourcePublic: [],
            }
        },
        mounted(){
            this.breadcrumbList = [
                {
                    name: 'root',
                    id: '0'
                }
            ];
            // 获取列表
            this.getResourceList();
        },
        methods:{
            addResOrEditBtn(val,type){
                let menu = this.breadcrumbList;
                let id = menu[menu.length-1].id;
                this.dialogData.editData = {};
                this.dialogData.YARNtitle = val;
                this.dialogData.editData.resourceId = id;
                this.dialogData.editData.level = menu.length;
                this.dialogData.editYARN = true;
                this.dialogData.opeType = type;
            }
        }
    }
</script>

<style lang="scss" scoped>
@import '~@/styles/resCommon.scss';
.resCommon .breadcrumb-wrap{
    padding: 20px 0;
    margin: 0;
}
</style>